const fs = require('fs');
const path = require('path');
const manifestFile = require('../src/manifest.json');
const pagesFile = require('../src/pages.json');

manifestFile['appid'] = 'wx3100093fc95f343f'
manifestFile['mp-weixin']['appid'] = 'wx3100093fc95f343f'
manifestFile['name'] = '橙事新人'
pagesFile["globalStyle"]["navigationBarTitleText"] = '橙事新人'

try {
  let styleFile = fs.readFileSync(path.resolve(__dirname, "../src/uni.scss"), "utf8").split('\n');
  styleFile.splice(0, 3)

  styleFile.splice(0, 0, ...[
    '$uni-color-primary: rgba(252, 175, 79);',
    '$theme-half: rgba(252, 175, 79, 0.5);',
    '$uni-color-primary-light: rgba(252, 175, 79, 0.15);'
  ])

  try {
    fs.writeFileSync(path.resolve(__dirname, "../src/uni.scss"), styleFile.join('\n'), "utf8");
  } catch (err) {
    console.log("log --> 样式文件修改失败！");
  }
  try {
    fs.writeFileSync(
      path.resolve(__dirname, '../src/manifest.json'),
      JSON.stringify(manifestFile, null, 2),
      'utf8'
    );
    fs.writeFileSync(
      path.resolve(__dirname, '../src/pages.json'),
      JSON.stringify(pagesFile, null, 2),
      'utf8'
    );
  } catch (err) {
    console.log("log --> manifest.json 文件修改失败！");
  }
} catch (err) {
  console.log("log --> 样式文件读取失败！");
}
